﻿using System;
using System.Collections.Generic;
using System.Linq;
using Chinook.Facade.Messaging;
using Chinook.Facade.ViewModel;

namespace Chinook.Web
{
    public partial class TestHareness : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //var empService = ChinookWebFactory.EmployeeAppService;
            //var result = empService.SearchEmployee(new EmployeeSearchRequest() { PageSize = 5, PageIndex = 2, Name = "Chang" });
            //empService.get
            ////Debug Code
            //var result = CustomerDao.GetPaged(6, 10);
            ////string Totalcnt =  CustomerDao.GetPaged(1,10).TotalCount.ToString();
            ////string TotalRec = CustomerDao.GetPaged(1, 10).;
           
            ReOrganizeCollection();
        }

        public void ReOrganizeCollection()
        {
            //*****Test Data Population (Start)
            var basicDocsViewModels = new List<BasicDocsViewModel>();

            //Group-01
            var basicDocsViewModel01 = new BasicDocsViewModel {SNoPrincipal = "1", Nature = "Principal_01"};
            var basicDocsViewModel02 = new BasicDocsViewModel { Nature = "Supplimentary_01", Remark = "Remark for 01" };
            var basicDocsViewModel03 = new BasicDocsViewModel { Nature = "Supplimentary_02" };
            var basicDocsViewModel04 = new BasicDocsViewModel { Nature = "Associative_01"};

            //Group-02
            var basicDocsViewModel05 = new BasicDocsViewModel { SNoPrincipal = "2", Nature = "Principal_02" };
            var basicDocsViewModel06 = new BasicDocsViewModel { Nature = "Supplimentary_01" };
            var basicDocsViewModel07 = new BasicDocsViewModel { Nature = "Supplimentary_02" };
            var basicDocsViewModel08 = new BasicDocsViewModel { Nature = "Associative_01"};

            //Group-03
            var basicDocsViewModel09 = new BasicDocsViewModel { SNoPrincipal = "3", Nature = "Principal_02" };
            var basicDocsViewModel10 = new BasicDocsViewModel { Nature = "Supplimentary_01", Remark = "Remark for 03" };
            var basicDocsViewModel11 = new BasicDocsViewModel { Nature = "Supplimentary_02" };

            //Group-04
            var basicDocsViewModel12 = new BasicDocsViewModel { SNoPrincipal = "4", Nature = "Principal_02" };
            var basicDocsViewModel13 = new BasicDocsViewModel { Nature = "Supplimentary_01"};
            var basicDocsViewModel14 = new BasicDocsViewModel { Nature = "Associative-0000" };
            var basicDocsViewModel15 = new BasicDocsViewModel { Nature = "Associative-0000", Remark = "Remark for 04" };
            var basicDocsViewModel16 = new BasicDocsViewModel { Nature = "Associative-0000" };
            var basicDocsViewModel17 = new BasicDocsViewModel { Nature = "Associative-0000" };
          

            basicDocsViewModels.Add(basicDocsViewModel01);
            basicDocsViewModels.Add(basicDocsViewModel02);
            basicDocsViewModels.Add(basicDocsViewModel03);
            basicDocsViewModels.Add(basicDocsViewModel04);
            basicDocsViewModels.Add(basicDocsViewModel05);
            basicDocsViewModels.Add(basicDocsViewModel06);
            basicDocsViewModels.Add(basicDocsViewModel07);
            basicDocsViewModels.Add(basicDocsViewModel08);
            basicDocsViewModels.Add(basicDocsViewModel09);
            basicDocsViewModels.Add(basicDocsViewModel10);
            basicDocsViewModels.Add(basicDocsViewModel11);
            basicDocsViewModels.Add(basicDocsViewModel12);
            basicDocsViewModels.Add(basicDocsViewModel13);
            basicDocsViewModels.Add(basicDocsViewModel14);
            basicDocsViewModels.Add(basicDocsViewModel15);
            basicDocsViewModels.Add(basicDocsViewModel16);
            basicDocsViewModels.Add(basicDocsViewModel17);

            var dicRemarks = new Dictionary<string, string> { { "1", "Remark for 01" }, { "2", String.Empty }, { "3", "Remark for 03" }, { "4", "Remark for 04" } };

            //*****Test Data Population (End)

            //Actual Logic

            //Remove the remarks in the original collection (Because we already kept it in dictionary object)
            basicDocsViewModels.ForEach(delegate(BasicDocsViewModel vm) { vm.Remark = ""; });

           //Position the Remarks in the last row for each group
           for (var i=1;i<=dicRemarks.Count;i++)
            {
                var idx = basicDocsViewModels.FindIndex(vm => vm.SNoPrincipal ==i.ToString());
                if (idx==0){continue;}
                basicDocsViewModels[idx - 1].Remark = dicRemarks[(i-1).ToString()];
            }
           //Position the Remarks only for the last group
            basicDocsViewModels[basicDocsViewModels.Count - 1].Remark = dicRemarks[dicRemarks.Count.ToString()];
        }
    }
}
